<template>
	<view v-if="isShow">
		<view>
			<image class="img" src="../../static/images/user.png"></image>
			<uni-card @click="toUpdate">
				修改密码
			</uni-card>
			<uni-card @click="aboutUs">
				关于我们
			</uni-card>
			<uni-card @click="quit">
				退出登录
			</uni-card>
		</view>
	</view>
	<view class="content" v-else>
		<form @submit="formSubmit">
		<view class="avatorWrapper">
			<view class="avator">
				<image class="img" src="../../static/user-unlogin.png" mode="widthFix"></image>
			</view>
		</view>
		<view class="form">
			<view class="inputWrapper">
				<input  class="input"  v-model="username" type="text" value="" placeholder="请输入用户名" />
				
			</view>
			<view class="inputWrapper">
				<input  class="input"  v-model="password"  type="password" value="" placeholder="请输入密码" />
			</view>
		</view>
		<button form-type="submit" class="loginBtn">确认登录</button>
		</form>
		<view style="color: red; margin-left: 80px;margin-top: 20px;" @click="goRegister">还没有账号？点击前往注册</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isShow:false,
				title: 'Hello',
				username:"",
				password:"",
			}
		},
		onLoad() {

		},
		methods: {
			
			goRegister(){
				uni.navigateTo({
					url:'/pages/register/register'
				})
			},
			toUpdate(){
				uni.navigateTo({
					url:'/pages/my/update'
				})
			},
			quit(){
				this.isShow=false;
				this.username='';
				this.password='';
			},
			aboutUs(){
				uni.navigateTo({
					url:'/pages/my/map'
				})
			},
			
			async formSubmit() {
				const res=await this.$myRequest({
					url:'user/login',
					method:'POST',
					data:{
						username:this.username,
						password:this.password
					}
				})
				console.log(res);
				if(res.data=="登录成功"){
					this.isShow=true;
				}
				else{
					uni.showToast({
						title:'用户名或密码错误！',
						icon:'error'
					})
				}
			}
			
		}
	}
</script>

<style>
	.img{
		width: 30%;
		height: 100px;
		border-radius: 5px;
	}
	.content {
		background: #aaff7f;
		width: 100vw;
		height: 100vh;
	}
	.avatorWrapper{
		height: 20vh;
		width: 100vw;
		display: flex;
		justify-content: center;
		align-items: flex-end;
	}
	.avator{
		width: 200upx;
		height: 200upx;
		overflow: hidden;
	}
	.avator .img{
		width: 100%
	}
	.form{
		padding: 0 100upx;
		margin-top: 80px;
	}
	.inputWrapper{
		width: 100%;
		height: 80upx;
		background: white;
		border-radius: 20px;
		box-sizing: border-box;
		padding: 0 20px;
		margin-top: 25px;
	}
	.inputWrapper .input{
		width: 100%;
		height: 100%;
		text-align: center;
		font-size: 15px;
	}
	.loginBtn{
		width: 50%;
		height: 80upx;
		background: #00aaff;
		border-radius: 50upx;
		margin-top: 50px;
		display: flex;
		justify-content: center;
		align-items: center;
		
	}
	.loginBtn .btnValue{
		color: white;
	}
	.forgotBtn{
		text-align: center;
		color: #EAF6F9;
		font-size: 15px;
		margin-top: 20px;
	}
</style>

